package dataBase;


import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.jdo.annotations.*;



import com.google.appengine.api.datastore.Blob;
import com.google.appengine.api.datastore.Email;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.PhoneNumber;
import com.google.appengine.api.datastore.Rating;


@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Business {
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
	@Persistent
	private String bizName;
	@Persistent
	private String bizType;
	@Persistent
	private String bizNum;
	@Persistent
	private Blob logoPic;
	@Persistent
	private PhoneNumber phoneNumber;
	@Persistent
	@Unique
	private Email email;
	@Persistent
	private String website;
	@Persistent
	private String background;
	@Persistent
	private String secBackground;
	@Persistent
	private String borderColor;
	@Persistent
	private int nextOrderID;
	@Persistent
	private Date createDate;
	@Persistent
	private Date modifiedDate;
	@Persistent
	private String skypeLogin;
	@Persistent
	private Integer numOfVotes;
	@Persistent
	private Double votesAvg;
	@Persistent
	private List<String> historyLog;
	@Persistent
	private Long[] orderUrgencyTime;
	/*@Persistent
	private Long lowOrderTime;
	@Persistent
	private Long mediumOrderTime;
	@Persistent
	private Long highOrderTime;*/
	
	public int getNumOfVotes() {
		if(numOfVotes==null)
			return 0;
		return numOfVotes;
	}

	public void setNumOfVotes(int numOfVotes) {
		this.numOfVotes = numOfVotes;
	}

	public double getVotesAvg() {
		if(votesAvg==null)
			return 0;
		return votesAvg;
	}

	public void setVotesAvg(double votesAvg) {
		this.votesAvg = votesAvg;
	}

	public String getSkypeLogin() {
		return skypeLogin;
	}

	public String isSkypeLogin() {
		return skypeLogin;
	}

	public void setSkypeLogin(String skypeLogin2) {
		this.skypeLogin = skypeLogin2;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date create) {
		this.createDate = create;
	}

	public Date getModifiedDate() {
		return modifiedDate;
	}

	public void setModifiedDate(Date modified) {
		this.modifiedDate = modified;
	}

	public List<Key> getAllOrdersList() {
		return allOrdersList;
	}

	public void setAllOrdersList(List<Key> allOrdersList) {
		this.allOrdersList = allOrdersList;
	}

	@Persistent
	private String userName;
	@Persistent
	private String password;
	@Persistent
	private Rating rank;
	@Persistent
	private List<Key> statusList = new ArrayList<Key>();
	@Persistent
	private List<Key> allOrdersList = new ArrayList<Key>();
	@Persistent
	private ArrayList<String> messages = new ArrayList<String>();
	@Persistent
	private ArrayList<Blob> ads = new ArrayList<Blob>();
	@Persistent
	private ArrayList<Key> adsKeys = new ArrayList<Key>();

    public Key getKey() {
		return key;
	}

	public void setKey(Key key) {
		this.key = key;
	}

	public String getBizName() {
		return bizName;
	}

	public void setBizName(String bizName) {
		this.bizName = bizName;
	}

	public Blob getLogoPic() {
		return logoPic;
	}

	public void setLogoPic(Blob logoPic) {
		System.out.println("set blob "+logoPic.hashCode());
		this.logoPic = logoPic;
	}

	public PhoneNumber getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(PhoneNumber phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public Email getEmail() {
		return email;
	}

	public void setEmail(Email email) {
		this.email = email;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Rating getRank() {
		return rank;
	}

	public void setRank(Rating rank) {
		this.rank = rank;
	}

	public List<Key> getStatusList() {
		return statusList;
	}

	public void setStatusList(List<Key> statusList) {
		this.statusList = statusList;
	}
	
	public void addToStatusList(Status status) {
		this.statusList.add(status.getKey());
	}
	
	public void removeFromStatusList(Status status) {
		this.statusList.remove(status);
	}
	
	public void removeFromAllOrdersList(Order order) {
		this.allOrdersList.remove(order);
	}
	public void addToAllOrdersList(Order order) {
		this.allOrdersList.add(order.getKey());
	}
	
	public void setMessages(ArrayList<String> messages) {
		// TODO Auto-generated method stub
		this.messages = messages;
		
	}

	public ArrayList<String> getMessages() {
		return messages;
	}

	public void setBizNum(String bizNum) {
		// TODO Auto-generated method stub
		this.bizNum = bizNum;
	}

	public String getBizNum() {
		return bizNum;
	}

	public int getNextOrderID() {
		return nextOrderID;
	}

	public void setNextOrderID(int nextOrderID) {
		this.nextOrderID = nextOrderID;
	}

	public String getBackground() {
		return background;
	}

	public void setBackground(String background) {
		this.background = background;
	}

	public String getSecBackground() {
		return secBackground;
	}

	public void setSecBackground(String secBackground) {
		this.secBackground = secBackground;
	}

	public String getBorderColor() {
		return borderColor;
	}

	public void setBorderColor(String borderColor) {
		this.borderColor = borderColor;
	}

	public String getWebsite() {
		if (website==null)
			return "";
		return website;
	}

	public void setWebsite(String website) {
		this.website = website;
	}

	public ArrayList<Blob> getAds() {
		return ads;
	}
	
	public void addAd(Ad ad) {
		this.ads.add(ad.getAdPic());
		this.adsKeys.add(ad.getKey());
	}

	public void setAds(ArrayList<Blob> ads) {
		this.ads = ads;
	}

	public ArrayList<Key> getAdsKeys() {
		return adsKeys;
	}

	public void setAdsKeys(ArrayList<Key> adsKeys) {
		this.adsKeys = adsKeys;
	}
	
	public String getBizType() {
		return bizType;
	}

	public void setBizType(String bizType) {
		this.bizType = bizType;
	}

	public List<String> getHistoryLog() {
		return historyLog;
	}

	public void setHistoryLog(List<String> historyLog) {
		this.historyLog = historyLog;
	}
	
	public void addHistoryLog(String record)
	{		
		if (record==null)
			return;
		
		if (historyLog==null)
			historyLog = new ArrayList<String>();
		
		historyLog.add(0, record);
	}

	public Long[] getOrderUrgencyTime() {
		if(orderUrgencyTime==null || orderUrgencyTime.length==0)
			return new Long[]{0L,0L,0L}; //new Long[]{604800000L,259200000L,86400000L};
		return orderUrgencyTime;
	}

	public void setOrderUrgencyTime(Long[] orderUrgencyTime) {
		this.orderUrgencyTime = orderUrgencyTime;
	}
	

	

	/*public Long getLowOrderTime() {
		return lowOrderTime;
	}

	public void setLowOrderTime(Long lowOrderTime) {
		this.lowOrderTime = lowOrderTime;
	}

	public Long getMediumOrderTime() {
		return mediumOrderTime;
	}

	public void setMediumOrderTime(Long mediumOrderTime) {
		this.mediumOrderTime = mediumOrderTime;
	}

	public Long getHighOrderTime() {
		return highOrderTime;
	}

	public void setHighOrderTime(Long highOrderTime) {
		this.highOrderTime = highOrderTime;
	}*/
}





